from django.shortcuts import render
from rest_framework_extensions.cache.mixins import CacheResponseMixin

from . import serializers
from .models import Area

# Create your views here.
from rest_framework.viewsets import ReadOnlyModelViewSet


class AreaInfoView(CacheResponseMixin, ReadOnlyModelViewSet):
    # serializer_class = serializers.AreInfoSerializer
    # queryset = Area.objects.filter(parent=None)

    def get_serializer_class(self):
        if self.action == "list":
            return serializers.AreInfoSerializer
        else:
            return serializers.AreaSubsInfoSerializer

    def get_queryset(self):
        if self.action == "list":
            return Area.objects.filter(parent=None)
        else:
            return Area.objects.all()